package cn.lzd.mr.count.writable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Created by lzd on 2018/5/12.
 */
public class WordCountR extends Reducer<LongWritable, WriteBean, LongWritable, WriteBean> {

    @Override
    protected void reduce(LongWritable key, Iterable<WriteBean> values, Context context) throws IOException, InterruptedException {
        String name = null;
        int len = 0;
        for (WriteBean value : values) {
            name = value.getStr();
            len += value.getStrLength();
        }

        WriteBean bean = new WriteBean();
        bean.setStr(name);
        bean.setStrLength(len);

        context.write(key, bean);

    }
}
